/**
 * 
 */
package edu.arizona.eller.mis.liferoulette.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import edu.arizona.eller.mis.liferoulette.db.dao.ActivityDAO;
import edu.arizona.eller.mis.liferoulette.db.dao.ActivityRatingDAO;
import edu.arizona.eller.mis.liferoulette.db.dao.UserPreferenceDAO;
import edu.arizona.eller.mis.liferoulette.entity.UserPreference;

/**
 * @author Blaine Boule - blaineb@email.arizona.edu
 *
 */
public class DatabaseManager extends SQLiteOpenHelper {
	private static final String _DB_NAME = "life-roulette.db";
	private static final int _DB_VERSION = 1;

	public DatabaseManager(Context context) {
		super(context, _DB_NAME, null, _DB_VERSION);
	}
		
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(UserPreferenceDAO._CREATE_STATEMENT);
		//Default Setting
		db.execSQL("INSERT INTO "+ UserPreferenceDAO._USER_PREFERENCE_TABLE + "(" +UserPreference._label +","+UserPreference._value+") VALUES ('MILES_SETTING','2')");
		db.execSQL("INSERT INTO "+ UserPreferenceDAO._USER_PREFERENCE_TABLE + "(" +UserPreference._label +","+UserPreference._value+") VALUES ('USEFB_SETTING','true')");
		db.execSQL("INSERT INTO "+ UserPreferenceDAO._USER_PREFERENCE_TABLE + "(" +UserPreference._label +","+UserPreference._value+") VALUES ('USESMS_SETTING','true')");
		db.execSQL(ActivityDAO._CREATE_STATEMENT);
		db.execSQL(ActivityRatingDAO._CREATE_STATEMENT);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + UserPreferenceDAO._USER_PREFERENCE_TABLE);
		db.execSQL("DROP TABLE IF EXISTS " + ActivityRatingDAO._ACTIVITY_RATING_TABLE);
		db.execSQL("DROP TABLE IF EXISTS " + ActivityDAO._ACTIVITY_TABLE);
		onCreate(db);
	}
}
